package com.application.sistercityapplication.cityinformationpage;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.application.sistercityapplication.main.R;
import com.application.sistercityapplication.model.CityInformationDetailItem;
import com.squareup.picasso.Picasso;

public class CityInformationDetailListAdapter extends BaseAdapter{
	
	private List<CityInformationDetailItem> _listCityInformDetail;
	private Context _context;
	private CityInformationDetailItem mag;
	private Activity _activity;
	private ViewHolderList holder;

	public CityInformationDetailListAdapter(List<CityInformationDetailItem> list,Context con,Activity ac){
		this._context = con;
		this._listCityInformDetail = list;
		this._activity = ac;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return _listCityInformDetail.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return _listCityInformDetail.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if(convertView== null){
			holder = new ViewHolderList();
			LayoutInflater inflater = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			
			convertView = inflater.inflate(R.layout.city_info_detail_each_item, null);
			holder.imageItem = (ImageView) convertView.findViewById(R.id.image_item);
			holder.textItem = (TextView) convertView.findViewById(R.id.text_item);
			holder.click_relative = (RelativeLayout) convertView.findViewById(R.id.click_relative);
			
			convertView.setTag(holder);
		}else{
			holder = (ViewHolderList) convertView.getTag();
		}
		mag = _listCityInformDetail.get(position);
		try{
			/*
			 * getImage from dummy
			 */
			Picasso.with(_context).load(mag.getImageDrawable()).into(holder.imageItem);
			holder.textItem.setText(mag.getDetailName());
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
		
		return convertView;
	}

	public class ViewHolderList{
		public ImageView imageItem;
		public TextView textItem;
		public RelativeLayout click_relative;
	}
}
